<template>
	<view class="wrapper" style="background: linear-gradient(#f29768 0%,#ffffff 60%) ;">
		<view class='searchGood'>
			<view class='search acea-row row-between-wrapper'>
				<view class='input acea-row row-between-wrapper'>
					<text class='iconfont icon-sousuo'></text>
					<input :placeholder='$t(`搜索商品名称`)' placeholder-class='placeholder' confirm-type='search'
						name="search" :value='where.keyword' @confirm="searchSubmit"></input>
				</view>
			</view>
		</view>
		
		<view class='productList'>
			<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scroll="scroll">
				<view v-for="(theme,index) in themeList" class="theme_item">
					<view v-if="theme.product_list.length>0" class="theme_title">{{theme.theme_name}}</view>
					<view v-if="theme.product_list.length>0" class='list acea-row row-between-wrapper'>
						<view class='item' hover-class='none'
							v-for="(item,index) in theme.product_list" :key="index" @click="godDetail(item)">
							<view class='pictrue' style="height: 460rpx;">
								<image :src='item.image'></image>
								<span class="pictrue_log_class"
									:class="is_switch === true ? 'pictrue_log_big' : 'pictrue_log'"
									v-if="item.activity && item.activity.type === '1' && $permission('seckill')">{{$t(`秒杀`)}}</span>
								<span class="pictrue_log_class"
									:class="is_switch === true ? 'pictrue_log_big' : 'pictrue_log'"
									v-if="item.activity && item.activity.type === '2' && $permission('bargain')">{{$t(`砍价`)}}</span>
								<span class="pictrue_log_class"
									:class="is_switch === true ? 'pictrue_log_big' : 'pictrue_log'"
									v-if="item.activity && item.activity.type === '3' && $permission('combination')">{{$t(`拼团`)}}</span>
							</view>
							<view class='text' :class='is_switch==true?"":"on"'>
								<view class='name line2'>{{item.store_name}}</view>
								<view class='money font-color' :class='is_switch==true?"":"on"'>{{$t(`￥`)}}<text
										class='num'>{{item.price}}</text></view>
								<view class='vip acea-row row-between-wrapper' :class='is_switch==true?"":"on"'>
									<view class='vip-money' v-if="item.vip_price && item.vip_price > 0">
										{{$t(`￥`)}}{{item.vip_price}}
										<image src='../../../static/images/vip.png'></image>
									</view>
									<view v-else></view>
									<view>{{$t(`已售`)}} {{item.sales}}{{$t(item.unit_name) || $t(`件`)}}</view>
								</view>
							</view>
						</view>
						<!-- 不是2的倍数，补齐 -->
						<view class='item' style="background-color: rgb(255,255,255,0)" hover-class='none' v-iv="theme.product_list.length%2==1">
							<view class='pictrue' style="height: 460rpx;"></view>
						</view>
					</view>
				</view>
				<view class='loadingicon acea-row row-center-wrapper' v-if='themeList.length > 0'>
					没有更多内容
				</view>
			</scroll-view>
		</view>
		<view class='noCommodity' v-if="themeList.length==0">
			<view class='emptyBox'>
				<image :src="imgHost + '/statics/images/no-thing.png'"></image>
				<view class="tips">{{$t(`暂无商品，去看点别的吧`)}}</view>
			</view>
		</view>
		<view v-if="scrollTopShow" class="back-top" @click="goTop">
			<text class="iconfont icon-xiangshang"></text>
		</view>
	</view>
</template>

<script>
	import home from '@/components/home';
	import {
		getThemProducts
	} from '@/api/store.js';
	import {
		mapGetters
	} from "vuex";
	import {
		goShopDetail
	} from '@/libs/order.js'
	import {
		HTTP_REQUEST_URL
	} from '@/config/app';
	export default {
		computed: mapGetters(['uid']),
		components: {
			home
		},
		data() {
			return {
				imgHost: HTTP_REQUEST_URL,
				themeList: [],
				is_switch: true,
				where: {
					keyword: '',
					type: 0,  // 类型1热门 2新品
					page: 1,
					limit: 20,
				},
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				scrollTopShow: false
			};
		},
		onLoad: function(options) {
			this.where.type = options.type;
			this.get_theme_list();
			if(this.where.type==2){
				wx.setNavigationBarTitle({
					title: '新品推荐'
				})
			}else{
				wx.setNavigationBarTitle({
					title: '热门推荐'
				})
			}
		},
		methods: {
			scroll(e) {
				this.scrollTopShow = e.detail.scrollTop > 150
				this.old.scrollTop = e.detail.scrollTop
			},
			goTop(e) {
				// 解决view层不同步的问题
				this.scrollTop = this.old.scrollTop
				this.$nextTick(() => {
					this.scrollTop = 0
				});
			},
			// 去详情页
			godDetail(item) {
				goShopDetail(item, this.uid).then(res => {
					uni.navigateTo({
						url: `/pages/goods_details/index?id=${item.id}`
					})
				})
			},
			searchSubmit: function(e) {
				this.where.keyword = e.detail.value
				this.get_theme_list();
			},
			//查找产品
			get_theme_list: function(isPage) {
				let that = this;
				getThemProducts(that.where).then(res => {
					let list = res.data;
					that.themeList = list
				}).catch(err => {
				});
			},
		},
		onPullDownRefresh() {},
		onReachBottom() {},
		// 滚动监听
		onPageScroll(e) {
			// 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
			uni.$emit('scroll');
		},
	}
</script>

<style scoped lang="scss">
	.acea-row.row-between-wrapper {
		justify-content: center;
	}
	.theme_title{
		text-align: center;
		color: black;
		line-height: 80rpx;
		font-size: 42rpx;
	}
	.scroll-Y {
		// margin-top: 86rpx;
		height: calc(100vh - 86rpx);
	}

	.wrapper {
		position: relative;
		max-height: 100vh;
		overflow: hidden;

		.back-top {
			position: absolute;
			right: 40rpx;
			bottom: 60rpx;
			width: 60rpx;
			height: 60rpx;
			border-radius: 50%;
			display: flex;
			justify-content: center;
			align-items: center;
			border: 1rpx solid #ccc;
			background-color: #fff;

			.icon-xiangshang {
				color: #ccc;
				font-weight: bold;
			}
		}
	}
	.productList{
		margin-top: 30rpx;
	}
	.productList .list .item {
		width: 345rpx;
		margin: 20rpx 10rpx;
		background-color: #fff;
		// border-radius: 20rpx;
	}

	.productList .list .item .pictrue {
		position: relative;
		width: 100%;
		height: 345rpx;

	}

	.productList .list .item .name {
		line-height: 42rpx;
		height: 84rpx;
	}
	
	.productList .list .item .pictrue image {
		width: 100%;
		height: 100%;
		// border-radius: 20rpx 20rpx 0 0;
	}

	.productList .list .item .text {
		padding: 20rpx 17rpx 26rpx 17rpx;
		font-size: 30rpx;
		color: #222;
	}

	.productList .list .item .text .money {
		font-size: 26rpx;
		font-weight: bold;
		margin-top: 8rpx;
		color: #000000 !important;
	}

	.productList .list .item .text .money .num {
		font-size: 36rpx;
		color: #000000;
		font-family: fangsong;

	}

	.productList .list .item .text .vip {
		font-size: 22rpx;
		color: #aaa;
		margin-top: 7rpx;
	}

	.productList .list .item .text .vip .vip-money {
		font-size: 24rpx;
		color: #282828;
		font-weight: bold;
		display: flex;
		align-items: center;
	}

	.productList .list .item .text .vip .vip-money image {
		width: 64rpx;
		height: 26rpx;
		margin-left: 4rpx;
	}

	.noCommodity {
		background-color: #fff;
		padding-bottom: 30rpx;

		.emptyBox {
			text-align: center;
			padding-top: 20rpx;

			.tips {
				color: #aaa;
				font-size: 26rpx;
			}

			image {
				width: 414rpx;
				height: 304rpx;
			}
		}
	}
	
	.searchGood .search .input {
		width: 598rpx;
		background-color: #f7f7f7;
		border-radius: 33rpx;
		padding: 0 15rpx;
		box-sizing: border-box;
		height: 66rpx;
	}
	
	.searchGood .search .input input {
		width: 492rpx;
		font-size: 28rpx;
	}
	
	.searchGood .search .input .placeholder {
		color: #999;
	}
	
	.searchGood .search .input .iconfont {
		color: #555;
		font-size: 35rpx;
	}
	
	.searchGood .search .bnt {
		width: 120rpx;
		text-align: center;
		height: 66rpx;
		line-height: 66rpx;
		font-size: 30rpx;
		color: #282828;
	}
	
	.searchGood .title {
		font-size: 28rpx;
		color: #999;
		margin: 50rpx 30rpx 25rpx 30rpx;
	}
	.searchGood{
		margin-top: 20rpx;
	}
	.searchGood .title .iconfont {
		font-size: 28rpx;
	}
	
	.searchGood .list {
		padding-left: 10rpx;
	}
	
	.searchGood .list .item {
		font-size: 26rpx;
		color: #454545;
		padding: 0 21rpx;
		height: 60rpx;
		border-radius: 3rpx;
		line-height: 60rpx;
		border: 1rpx solid #aaa;
		margin: 0 0 20rpx 20rpx;
	}
	
	.searchGood .list .item.history-item {
		height: 50rpx;
		border: none;
		border-radius: 25rpx;
		background-color: #F7F7F7;
		line-height: 50rpx;
	}
	
	.searchGood .line {
		border-bottom: 1rpx solid #eee;
		margin: 20rpx 30rpx 0 30rpx;
	}
</style>